home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / modelers / geomview / source.lha / Geomview / include / fexpr.h < prev    next >
C/C++ Source or Header  |  1993-08-17  |  5KB  |  160 lines

  1. /* expression, version 1.0 */
  2.  
  3. typedef int expr_var;
  4. typedef struct {
  5.   double real;
  6.   double imag;
  7. } fcomplex;
  8.  
  9. struct expression {
  10.   int nvars;
  11.   char **varnames;
  12.   fcomplex *varvals;
  13.   int nelem;            /* number of elements in the vector. */
  14.   struct expr_elem *elems;
  15. };
  16.  
  17. typedef double (*func_double)(double);
  18. typedef double (*func_double_double)(double, double);
  19.  
  20. typedef void (*func_complex)(fcomplex *source, fcomplex*result);
  21. typedef void (*func_complex_complex)(fcomplex *source1, fcomplex *source2, fcomplex*result);
  22.  
  23. struct expr_elem {
  24.   enum expr_op {
  25.     MONOP,
  26.     BINOP,
  27.     MONFUNC,
  28.     BINFUNC,
  29.     PUSHVAR,
  30.     PUSHNUM
  31.   } op;
  32.   union {
  33.     struct {
  34.       char op;
  35.     } monop;
  36.     struct {
  37.       char op;
  38.     } binop;
  39.     struct {
  40.       func_double func;
  41.       func_complex cfunc;
  42.     } monfunc;
  43.     struct {
  44.       func_double_double func;
  45.       func_complex_complex cfunc;
  46.     } binfunc;
  47.     struct {
  48.       int varnum;
  49.     } pushvar;
  50.     struct {
  51.       double number;
  52.     } pushnum;
  53.   } u;
  54. };
  55.  
  56. extern struct expression *expr_new(void);
  57. extern void     expr_free(struct expression *);
  58. extern char    *expr_parse(struct expression *expr, char *e);
  59. extern double   expr_evaluate(struct expression *e);
  60. extern void     expr_evaluate_some(struct expression *e, expr_var v,
  61.                    double min, double max, int npoints,
  62.                    double *buffer);
  63. extern void     expr_evaluate_complex(struct expression *e, fcomplex *op);
  64. extern expr_var expr_create_variable(struct expression *e, char *name,
  65.                      double val);
  66. extern void     expr_set_variable(struct expression *e, expr_var v,
  67.                   double val);
  68. extern void     expr_set_variable_complex(struct expression *e, expr_var v,
  69.                       fcomplex *val);
  70. extern double   expr_get_variable(struct expression *e, expr_var v);
  71. extern void     expr_get_variable_complex(struct expression *e, expr_var v,
  72.                       fcomplex *op);
  73. extern void     expr_copy_variables(struct expression *source, struct expression *dest);
  74.  
  75.  
  76. extern struct expr_monfunc {
  77.   char *name;
  78.   func_double func;
  79.   func_complex cfunc;
  80. } expr_monfuncs[];
  81.  
  82. extern struct expr_binfunc {
  83.   char *name;
  84.   func_double_double func;
  85.   func_complex_complex cfunc;
  86. } expr_binfuncs[];
  87.  
  88.  
  89. extern void fcomplex_re(fcomplex *,fcomplex *);
  90. extern void fcomplex_im(fcomplex *,fcomplex *);
  91. extern void fcomplex_abs(fcomplex *,fcomplex *);
  92. extern void fcomplex_log(fcomplex *,fcomplex *);
  93. extern void fcomplex_log10(fcomplex *,fcomplex *);
  94. extern void fcomplex_sqrt(fcomplex *,fcomplex *);
  95. extern void fcomplex_cos(fcomplex *,fcomplex *);
  96. extern void fcomplex_arccos(fcomplex *,fcomplex *);
  97. extern void fcomplex_sin(fcomplex *,fcomplex *);
  98. extern void fcomplex_arcsin(fcomplex *,fcomplex *);
  99. extern void fcomplex_tan(fcomplex *,fcomplex *);
  100. extern void fcomplex_arctan(fcomplex *,fcomplex *);
  101. extern void fcomplex_cot(fcomplex *,fcomplex *);
  102. extern void fcomplex_sec(fcomplex *,fcomplex *);
  103. extern void fcomplex_csc(fcomplex *,fcomplex *);
  104. extern void fcomplex_cosh(fcomplex *,fcomplex *);
  105. extern void fcomplex_sinh(fcomplex *,fcomplex *);
  106. extern void fcomplex_tanh(fcomplex *,fcomplex *);
  107. extern void fcomplex_arccosh(fcomplex *,fcomplex *);
  108. extern void fcomplex_arcsinh(fcomplex *,fcomplex *);
  109. extern void fcomplex_arctanh(fcomplex *,fcomplex *);
  110. extern void fcomplex_floor(fcomplex *,fcomplex *);
  111. extern void fcomplex_round(fcomplex *,fcomplex *);
  112. extern void fcomplex_ceiling(fcomplex *,fcomplex *);
  113. extern void fcomplex_exp(fcomplex *,fcomplex *);
  114.  
  115. extern void fcomplex_pow(fcomplex *,fcomplex *,fcomplex *);
  116. extern void fcomplex_atan2(fcomplex *,fcomplex *,fcomplex *);
  117.  
  118. extern double freal_re(double);
  119. extern double freal_im(double);
  120. extern double freal_cot(double);
  121. extern double freal_sec(double);
  122. extern double freal_csc(double);
  123.  
  124. extern void fcomplex_monstub(fcomplex *,fcomplex *);
  125. extern void fcomplex_binstub(fcomplex *,fcomplex *, fcomplex *);
  126. extern double freal_monstub(double);
  127. extern double freal_binstub(double,double);
  128.  
  129. #define DEFAULT_EXPR_MONFUNCS \
  130.   {"re",     freal_re,      fcomplex_re}, \
  131.   {"im",     freal_im,      fcomplex_im}, \
  132.   {"abs",         fabs,     fcomplex_abs}, \
  133.   {"log",          log,     fcomplex_log}, \
  134.   {"log10",        log10,   fcomplex_log10}, \
  135.   {"sqrt",         sqrt,    fcomplex_sqrt}, \
  136.   {"cos",          cos,     fcomplex_cos}, \
  137.   {"arccos",       acos,    fcomplex_arccos}, \
  138.   {"sin",          sin,     fcomplex_sin}, \
  139.   {"arcsin",       asin,    fcomplex_arcsin}, \
  140.   {"tan",          tan,     fcomplex_tan}, \
  141.   {"arctan",       atan,    fcomplex_arctan}, \
  142.   {"cot",    freal_cot,     fcomplex_cot}, \
  143.   {"sec",    freal_sec,     fcomplex_sec}, \
  144.   {"csc",    freal_csc,     fcomplex_csc}, \
  145.   {"cosh",         cosh,    fcomplex_cosh}, \
  146.   {"sinh",         sinh,    fcomplex_sinh}, \
  147.   {"tanh",         tanh,    fcomplex_tanh}, \
  148.   {"arccosh",      acosh,   fcomplex_arccosh}, \
  149.   {"arcsinh",      asinh,   fcomplex_arcsinh}, \
  150.   {"arctanh",      atanh,   fcomplex_arctanh}, \
  151.   {"floor",        floor,   fcomplex_floor}, \
  152.   {"round",        rint,    fcomplex_round}, \
  153.   {"ceiling",      ceil,    fcomplex_ceiling}, \
  154.   {"exp",          exp,     fcomplex_exp}
  155.  
  156. #define DEFAULT_EXPR_BINFUNCS \
  157.   {"pow", pow, fcomplex_pow}, \
  158.   {"arctan2", atan2, fcomplex_atan2}
  159.  
  160.